package lzzsrj.union.message.rabbitMq.producer;

import com.alibaba.fastjson.JSONObject;
import lzzsrj.union.message.common.producer.Producer;
import lzzsrj.union.message.common.bean.UnionMessage;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

@Component
public class ProducerRabbitMQ implements Producer {

    @Autowired
    private AmqpTemplate rabbitTemplate;

    @Override
    public Boolean send(String topic, String tag, UnionMessage message) {
        return this.send(topic, tag, message, 0L, TimeUnit.SECONDS);
    }

    @Override
    public Boolean send(String topic, String tag, UnionMessage message, Long delay, TimeUnit timeUnit) {
        rabbitTemplate.convertAndSend(topic, JSONObject.toJSONString(message));
        return Boolean.TRUE;
    }
}
